package com.itheima.contact.web;

import com.itheima.contact.domain.User;
import com.itheima.contact.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author ${Azer}
 * @LOVE,,,
 * @Date 2021/9/19 17:19
 */
//数据回显
@WebServlet("/queryUserById")
public class QueryUserById extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        int id = Integer.parseInt(request.getParameter("id"));

        UserService userService=new UserService();

        User user = userService.queryUserById(id);

        //把用户对象存储到request域对象中
        request.setAttribute("user",user);

        //转发到修改页面
        request.getRequestDispatcher("/update.jsp").forward(request,response);

    }
}
